Skip to content

feat(cli): add --info flag to extract lightweight JSON metadata#2205

Open
saitejabandaru-in wants to merge 1 commit into
microsoft:mainfrom
saitejabandaru-in:feat/info-metadata-flag
Open

feat(cli): add --info flag to extract lightweight JSON metadata#2205
saitejabandaru-in wants to merge 1 commit into
microsoft:mainfrom
saitejabandaru-in:feat/info-metadata-flag

Conversation

@saitejabandaru-in

Copy link
Copy Markdown

Summary

Resolves #2182.

This PR adds a lightweight --info flag (and a public API method get_metadata()) that outputs structured JSON metadata (path, size, mime type, and detected converter) for a given file or stream without executing the full conversion pipeline.

This is highly useful for triage, cost/duration estimation, and routing in AI agent pipelines, where agents want to know what a document is before committing to full, potentially expensive conversion paths.

Examples

$ markitdown --info example.docx
{
  "mime_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
  "detected_converter": "DocxConverter",
  "size_bytes": 135824,
  "path": "example.docx"
}

Changes

  • Implemented public get_metadata(), get_metadata_local(), and get_metadata_stream() methods in the MarkItDown class (_markitdown.py) to resolve and return metadata by querying the accepts() method of registered converters.
  • Added a --info option to the CLI (__main__.py) which triggers get_metadata() and outputs the results as JSON.
  • Added comprehensive unit tests in test_module_misc.py (test_get_metadata()) and test_cli_misc.py (test_info_flag()).
  • Updated existing CLI tests in test_cli_misc.py to use sys.executable instead of the hardcoded "python" command, ensuring they run correctly on systems (like macOS) that only have python3 on their PATH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add \markitdown --info FILE\ flag to emit document metadata as JSON (no full conversion)

1 participant